const tree = {
    name: '中国',
    children: [
        {
            name: '北京',
            children: [
                {
                    name: '朝阳群众'
                },
                {
                    name: '海淀区'
                },
                {
                    name: '昌平区'
                }
            ]
        },
        {
            name: '浙江省',
            children: [
                {
                    name: '杭州市',
                    code: '0571',
                },
                {
                    name: '嘉兴市'
                },
                {
                    name: '绍兴市'
                },
                {
                    name: '宁波市'
                }
            ]
        }
    ]
};
let target = {}
function getTreeName(tree, targetName) {
    const {name,code,children} = tree
    if (name === targetName) {
        target = tree
        return;
    }
    if (children){
        children.forEach(item => getTreeName(item, targetName))
    }
    return target
}

console.log(getTreeName(tree, '杭州市'));
